//package com.fowo.api.service.handleWork;
//
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.fowo.api.entity.PurchaseApplication;
//import com.fowo.api.entity.PurchaseApplicationProduct;
//import com.fowo.api.model.purchase.application.PurchaseApplicationPushPurchaseOrderAction;
//import com.fowo.api.model.purchase.order.PurchaseOrderVo;
//import com.fowo.api.model.purchase.order.product.PurchaseOrderProductItemVo;
//import com.fowo.api.service.PurchaseOrderProductService;
//import com.fowo.api.service.PurchaseOrderService;
//import com.fowo.api.service.impl.PurchaseApplicationProductServiceImpl;
//import com.fowo.api.service.impl.PurchaseApplicationServiceImpl;
//import com.fowo.api.service.impl.PurchaseOrderProductServiceImpl;
//import com.fowo.api.service.impl.PurchaseOrderServiceImpl;
//import com.fowo.api.sys.model.SysUserVo;
//import com.fowo.api.sys.service.SysUserService;
//import com.fowo.api.user.model.JwtUserInfo;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.ui.context.Theme;
//import org.springframework.util.Assert;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//@Component
//public class PushPurchaseOrder implements PurchaseApplicationPushPurchaseOrderAction {
//
//    @Resource
//    private PurchaseApplicationServiceImpl purchaseApplicationServiceImpl;
//
//    @Resource
//    protected PurchaseApplicationProductServiceImpl purchaseApplicationProductService;
//
//    @Resource
//    private PurchaseOrderServiceImpl purchaseOrderService;
//
//    @Resource
//    private PurchaseOrderProductServiceImpl PurchaseOrderProductService;
//    @Resource
//    private SysUserService userService;
//
//
//    private  final Object obj=new Object();
//    @Override
//    public void run(Long id){
//        synchronized (obj){
//            PurchaseApplication purchaseApplication = purchaseApplicationServiceImpl.getById(id);
//            Assert.notNull(purchaseApplication,"没找到这个采购申请单!");
//            Assert.isTrue(purchaseApplication.getStauts().equals("1"),"未审核不能下推采购订单!");
//            List<PurchaseApplicationProduct> listProduct = purchaseApplicationProductService.list(Wrappers.<PurchaseApplicationProduct>query()
//                    .lambda()
//                    .eq(PurchaseApplicationProduct::getPurchaseOrderApplicationId, id));
//            Long aLong = addPurchaseOrder(purchaseApplication, listProduct);
//            purchaseApplication.setPurchaseOrderId(aLong.toString());
//            purchaseApplicationServiceImpl.updateById(purchaseApplication);
//        }
//    }
//
//    @Transactional(rollbackFor = Exception.class)
//    public Long addPurchaseOrder(PurchaseApplication purchaseApplication,
//                                  List<PurchaseApplicationProduct> listProduct) {
//        Long aLong=null;
//        PurchaseOrderVo purchaseOrder=new PurchaseOrderVo();
//        purchaseOrder.setStauts("0");
//        purchaseOrder.setApplicationDep(purchaseApplication.getApplicationDep());
//        purchaseOrder.setApplicationDepName1(purchaseApplication.getApplicationDepName1());
//        purchaseOrder.setApplication(purchaseApplication.getApplication());
//        purchaseOrder.setPurchasesDate(purchaseApplication.getApplicationDate());
//        String Remarks="(原材料)采购申请单:"+purchaseApplication.getPurchaseApplicationOrderCode();
//        purchaseOrder.setRemarks(purchaseApplication.getRemarks()!=null?purchaseApplication.getRemarks()+":"+Remarks:Remarks);
//        purchaseOrder.setSupplierId(purchaseApplication.getSupplierId());
//        List<PurchaseOrderProductItemVo> list=new ArrayList<>();
//        for(int i=0;i<listProduct.size();i++){
//            PurchaseApplicationProduct purchaseApplicationProduct = listProduct.get(i);
//            PurchaseOrderProductItemVo PurchaseOrderProductItemVo=new PurchaseOrderProductItemVo();
//            PurchaseOrderProductItemVo.setSku(purchaseApplicationProduct.getSku());
//            PurchaseOrderProductItemVo.setProductId(purchaseApplicationProduct.getProductId());
//            PurchaseOrderProductItemVo.setProductName(purchaseApplicationProduct.getProductName());
//            PurchaseOrderProductItemVo.setApplicationDep(purchaseApplicationProduct.getApplicationDep());
//            PurchaseOrderProductItemVo.setApplicationNum(purchaseApplicationProduct.getQuantity());
//            PurchaseOrderProductItemVo.setApplicationUnit(purchaseApplicationProduct.getApplicationUnit());
//            PurchaseOrderProductItemVo.setArrivalDate(purchaseApplicationProduct.getArrivalDate());
//            PurchaseOrderProductItemVo.setRemarks(purchaseApplicationProduct.getRemarks());
//            list.add(PurchaseOrderProductItemVo);
//        }
//        purchaseOrder.setPurchaseOrde(list);
//        try {
//             aLong = purchaseOrderService.create(purchaseOrder);
//        } catch (Exception e) {
//            throw new RuntimeException();
//        }
//        return  aLong;
//    }
//
//}
